<?

// $Id: 

import("izz.service.RetrieveService");
import('iforum.web.iForumWebAppContext');

class listthreadService extends RetrieveService
{

	function execute()
	{
		$context = Singleton::instance('iForumWebAppContext');
		$request = &$context->getRequest();
		$forumid = &$request->getParameter('fid');
		
		$currentpage = &$request->getParameter('page');
		if (!isset($currentpage) || $currentpage=='')
		{
			$currentpage = 1;
		}

		$daofactory = $context->getDaoFactory();

		$tdao = $daofactory->getThreadDAO();
		$fdao = $daofactory->getForumDAO();
		$forum = $fdao->getForum($forumid);
		
		$topics = &$tdao->getThreadsByForumId($forumid, 20, ($currentpage-1)*20);
		foreach ($topics as $key=>$value)
		{
			$topics[$key]['postTime'] = date("Y-m-j H:i:s",$value['postTime']);
			$topics[$key]['lastPostTime'] = date("Y-m-j H:i:s",$value['lastPostTime']);
		}
		
		
		$result = array();
		$result['forum'] = $forum;
		$result['topics'] = $topics;
		$result['topiccount'] = $forum['fTopic'];
		$result['pagecount'] = ceil($result['topiccount']/20);
		$result['currentpage'] = $currentpage;
		
		$this->_result = $result;
		return true;
	}
	
}

?>